#include"./httplib.h"
using namespace httplib;

void HelloGavin(const Request &req, Response &rsp)
{
    rsp.body = "Hello Gavin!";
    rsp.status = 200;
}
void Numbers(const Request &req, Response &rsp)
{
    std::string num = req.matches[1]; // matches存放正则表达式匹配的规则数据，也就是()里面单独捕捉的数据
    rsp.set_content(num, "Text/plain");
    rsp.status = 200; // 向rsp.body里面添加数据
}
void Multipart(const Request &req, Response &rsp)
{
    if(req.has_file("file1") == false)
    {
        rsp.status = 100;
        return;
    }

    const auto& file = req.get_file_value("file1");    
    std::cout << file.filename << std::endl;
    std::cout << file.content << std::endl;

    rsp.status = 200;
}
int main()
{
    Server server;

    // 设置一个静态资源目录
    server.set_mount_point("/","./www");

    // 添加请求：处理函数映射信息
    server.Get("/hi",HelloGavin);
    // 正则表达式：\d表示数字，+表示匹配匹配前面的字符一次或者多次，（）表示单独捕捉数据
    server.Get("/numbers/(\\d+)",Numbers);
    server.Post("/multipart",Multipart);
    server.listen("0.0.0.0", 8888);

    return 0;
}